package com.algorithm.base.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * 后序遍历
 * 左右中
 *
 * @author Amadeus
 * @date 2023/10/27
 */
public class PostOrderTraversal {

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        postOrder(root, list);
        return list;
    }

    public void postOrder(TreeNode node, List<Integer> list) {
        if (node == null) {
            return;
        }
        postOrder(node.left, list);
        postOrder(node.right, list);
        list.add(node.val);
    }
}
